﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Reflection;

namespace KC.DataAccess.Global
{
	/// <summary>Assembly and reflection based methods</summary>
	public static class Reflection
	{
		/// <summary>Gets the compile date and time of the assembly.</summary>
		/// <returns>Date and time the assembly was compiled.</returns>
		public static DateTime GetAssemblyBuildDate()
		{
			string filename = Assembly.GetCallingAssembly().Location;
			byte[] b = new byte[2048];
			Stream s = null;

			try {
				s = new FileStream(filename, FileMode.Open, FileAccess.Read);
				s.Read(b, 0, 2048); }
			finally { if (s != null) s.Close(); }

			int i = BitConverter.ToInt32(b, 60);
			DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0);
			return dt.AddSeconds(System.BitConverter.ToInt32(b, i + 8)).AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours);
		}
	}
}
